﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Xml.Linq;
using Microsoft.Office.OneNote;
using System.Globalization;
using System.Reflection;

namespace OneNoteFrameworkTests.PageContentTests
{
    [TestFixture]
    public class OutlineTests : PageTestBase
    {
        [Test]
        public void DeserializePageTitleOE()
        {
            const string xml = @"
<one:Page xmlns:one=""http://schemas.microsoft.com/office/onenote/2007/onenote"" ID=""{9A1633D5-6266-4ED9-AF44-4C8B9456391B}{1}{B0}"" name=""Untitled page"" dateTime=""2007-10-26T16:49:12.000Z"" lastModifiedTime=""2007-11-01T15:37:27.000Z"">
  <one:PageSettings RTL=""false"" color=""automatic"">
    <one:PageSize>
      <one:Automatic />
    </one:PageSize>
    <one:RuleLines visible=""false"" />
  </one:PageSettings>
  <one:Title style=""font-family:Calibri;font-size:17.0pt"" lang=""en-US"">
    <one:OE author=""Baba Yaga"" lastModifiedBy=""jachymko"" 
            creationTime=""2007-10-26T16:49:12.000Z"" 
            lastModifiedTime=""2007-10-26T16:49:12.000Z"" 
            alignment=""center""
            objectID=""{811AA777-1465-457B-AEBD-1B08AAA67B2A}{15}{B0}"" >
      <one:T><![CDATA[]]></one:T>
    </one:OE>
  </one:Title>
</one:Page>";

            OneNotePage page = DeserializePage(xml);
            Assert.IsNotNull(page);

            Assert.IsTrue(page.PageSettings.Size.IsAutomatic);
            Assert.IsFalse(page.PageSettings.RightToLeft);
            Assert.AreEqual(OneNoteColor.Automatic, page.PageSettings.Color);

            Assert.AreEqual("font-family:Calibri;font-size:17.0pt", page.Title.Style);
            Assert.AreEqual(CultureInfo.GetCultureInfo("en-US"), page.Title.Language);

            Assert.AreEqual("Baba Yaga", page.Title.OutlineElement.Author);
            Assert.AreEqual(OneNoteAlignment.Center, page.Title.OutlineElement.Alignment);
        }

        [Test]
        public void DeserializeOutline()
        {
            const string TestXml = @"
<one:Page xmlns:one=""http://schemas.microsoft.com/office/onenote/2007/onenote""
          ID=""{8BA0F240-9DDF-40CB-876C-F5686CBBBA94}{1}{B0}"" 
          name=""TestPage""
          dateTime=""2007-10-06T10:42:16.000Z""
          lastModifiedTime=""2007-10-06T10:59:58.000Z""
          style=""font-family:Calibri;font-size:11.0pt""
          lang=""cs"">

  <one:PageSettings RTL=""false"" color=""automatic"">
    <one:PageSize>
      <one:Automatic />
    </one:PageSize>
  </one:PageSettings>
  <one:Outline author=""Jachym Kouba"" 
               lastModifiedBy=""Jachym Kouba"" 
               lastModifiedTime=""2007-10-06T10:48:03.000Z""
               objectID=""{200C2454-7E39-46A3-B536-34DCCE7A9569}{28}{B0}"">
  </one:Outline>

  <one:Outline author=""Mazlo-zloun"" 
               lastModifiedBy=""Mazlo-zloun"" 
               lastModifiedTime=""2007-10-06T10:48:03.000Z""
               objectID=""{200C2454-7E39-46A3-B536-34DCCE7A90A0}{29}{B0}"">
  </one:Outline>
</one:Page>
";

            OneNotePage page = DeserializePage(TestXml);
            Assert.IsNotNull(page);

            Assert.AreEqual("TestPage", page.Name);
            Assert.AreEqual(CultureInfo.GetCultureInfo("cs"), page.Language);
            Assert.IsNotNull(page.Outlines);
            Assert.AreEqual(2, page.Outlines.Count);

            OneNoteOutline outline1 = page.Outlines[0];
            Assert.IsNotNull(outline1);
            Assert.AreEqual("Jachym Kouba", outline1.Author);

            OneNoteOutline outline2 = page.Outlines[1];
            Assert.IsNotNull(outline2);
            Assert.AreEqual("Mazlo-zloun", outline2.Author);
        }

    }
}
